<?php

class aetherController extends controllerBase {
	protected $mode = AETHER_BOTH;
	protected $view = false;
	protected $helpers = array();
	protected $models = array();
	protected $beforeFilters = array();
	protected $beforeAfter = array();

	function closeMessage() {
		if(!$this->params['ajax']) {
			$this->h->core->redirect($_GET['redirect']);
		}
		$this->h->message->closeMessage($this->params['id']);
		if($this->params['ajax']) {
			echo json_encode(array('success' => true));
		}
	}

	function packJs() {
		header('Content-Type: text/javascript');
		if($this->aether->config->get('general', 'appMode')==AETHER_PRODUCTION) {
			header('Cache-Control: public');
			header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time()+60*60*24*365));
			header('Pragma: ');
		}
		$name = 'js';
		foreach($_GET['files'] as $file) {
			$name .= '-'.str_replace('.', '', $file);
		}
		if($this->aether->cache->isAvailable($name) && $this->aether->config->get('general', 'appMode')==AETHER_PRODUCTION) {
			echo $this->aether->cache->get($name);
		} else {
			ob_start();
			foreach($_GET['files'] as $file) {
				$file = str_replace('..', 'bs', $file);
				if(file_exists('app/js/'.$file)) {
					require('app/js/'.$file);
				} else if(file_exists('core/js/'.$file)) {
					require('core/js/'.$file);
				}
				echo NL;
			}
			$this->aether->cache->set($name, ob_get_flush());
		}
	}

	function packCss() {
		header('Content-Type: text/css');
		if($this->aether->config->get('general', 'appMode')==AETHER_PRODUCTION) {
			header('Cache-Control: public');
			header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time()+60*60*24*365));
			header('Pragma: ');
		}
		$this->load('class/browserDetection');
		$info = new Browser;
		$browser = $info->getBrowser();
		$version = $info->getVersion();
		$name = 'css';
		foreach($_GET['files'] as $file) {
			$name .= ' '.$file;
		}
		$name .= ' '.$browser.' '.$version;
		$name = md5($name);
		if($this->aether->cache->isAvailable($name) && $this->aether->config->get('general', 'appMode')==AETHER_PRODUCTION) {
			echo $this->aether->cache->get($name);
		} else {
			ob_start();
			foreach($_GET['files'] as $file) {
				$file = str_replace('..', 'bs', $file);
				if(file_exists('app/css/'.$file)) {
					require('app/css/'.$file);
				} else if(file_exists('core/css/'.$file)) {
					require('core/css/'.$file);
				}
				echo NL;
			}
			$this->aether->cache->set($name, ob_get_flush());
		}
	}
}

?>
